import reader
from reader import *
import sexprs
from sexprs import *
import tag_parser
from tag_parser import *


sexpr, remaining = AbstractSchemeExpr.parse('(LAMBDA (X) (LAMBDA (Y Z) ((LAMBDA (X V) (F Z X)) (+ V Z X))))')
sexpr = sexpr.debruijn().annotateTC()
print(sexpr)
#print('(LAMBDA (X) (LAMBDA (Y Z) {(LAMBDA (X V) {Ff Zb01 Xp0}) (+f Vf Zp1 Xb00)}))')
#print('(LAMBDA (X) (LAMBDA (Y Z) {(LAMBDA (X V) {Ff Zb01 Xp0}) (+f Vf Zp1 Xb00)}))'.lower() == str(sexpr).lower())

sexpr, remaining = AbstractSchemeExpr.parse('(LAMBDA X (LAMBDA (Y X) (LIST (IF Y X (IF Z T 2)) (OR (LAMBDA (X) (X Y)) X Y) 22 (D X (+ X Y)) (LAMBDA C (LAMBDA (A B . C) (LAMBDA (E F G) (LAMBDA (H I J) (IF (OR A B C) (D E F G) (D H (+ I J))))))))))')
sexpr = sexpr.debruijn().annotateTC()
print(sexpr)
#print('(LAMBDA X (LAMBDA (Y X) {LISTf (IF Yp0 Xp1 (IF Zf Tf 2)) (OR (LAMBDA (X) {Xp0 Yb00}) Xp1 Yp0) 22 (Df Xp1 (+f Xp1 Yp0)) (LAMBDA C (LAMBDA (A B . C) (LAMBDA (E F G) (LAMBDA (H I J) (IF (OR Ab10 Bb11 Cb12) {Df Eb00 Fb01 Gb02} {Df Hp0 (+f Ip1 Jp2)})))))}))')
#print('(LAMBDA X (LAMBDA (Y X) {LISTf (IF Yp0 Xp1 (IF Zf Tf 2)) (OR (LAMBDA (X) {Xp0 Yb00}) Xp1 Yp0) 22 (Df Xp1 (+f Xp1 Yp0)) (LAMBDA C (LAMBDA (A B . C) (LAMBDA (E F G) (LAMBDA (H I J) (IF (OR Ab10 Bb11 Cb12) {Df Eb00 Fb01 Gb02} {Df Hp0 (+f Ip1 Jp2)})))))}))'.lower() == str(sexpr).lower())


sexpr, remaining = AbstractSchemeExpr.parse('(DEFINE FOO (LAMBDA (X) (IF (= X 1) (* 5 (HOO X)) (IF (= X 2) (HOO X) (FOO X)))))')
sexpr = sexpr.debruijn().annotateTC()
print(sexpr)
#print('(DEFINE FOOf (LAMBDA (X) (IF (=f Xp0 1) {*f 5 (HOOf Xp0)} (IF (=f Xp0 2) {HOOf Xp0} {FOOf Xp0}))))')
#print('(DEFINE FOOf (LAMBDA (X) (IF (=f Xp0 1) {*f 5 (HOOf Xp0)} (IF (=f Xp0 2) {HOOf Xp0} {FOOf Xp0}))))'.lower() == str(sexpr).lower())

sexpr, remaining = AbstractSchemeExpr.parse('(LAMBDA (A B C) (LAMBDA (E F G) (LIST (OR A B (OR C D)) (* G O G O) (LAMBDA Y (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (X Y)))))))))))) (IF (= 9 2) (OR 1 2 3) A) (IF A B (IF A B (IF A B C))) "bye bye")))')
sexpr = sexpr.debruijn().annotateTC()
print(sexpr)
#print('(LAMBDA (A B C) (LAMBDA (E F G) {LISTf (OR Ab00 Bb01 (OR Cb02 Df)) (*f Gp2 Of Gp2 Of) (LAMBDA Y (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X {Xp0 Yb90}))))))))))) (IF (=f 9 2) (OR 1 2 3) Ab00) (IF Ab00 Bb01 (IF Ab00 Bb01 (IF Ab00 Bb01 Cb02))) "bye bye"}))')
#print('(LAMBDA (A B C) (LAMBDA (E F G) {LISTf (OR Ab00 Bb01 (OR Cb02 Df)) (*f Gp2 Of Gp2 Of) (LAMBDA Y (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X (LAMBDA X {Xp0 Yb90}))))))))))) (IF (=f 9 2) (OR 1 2 3) Ab00) (IF Ab00 Bb01 (IF Ab00 Bb01 (IF Ab00 Bb01 Cb02))) "bye bye"}))'.lower() == str(sexpr).lower())




